home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / xml / dom / domreg.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  81 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from xml.dom.minicompat import *
  5. well_known_implementations = {
  6.     'minidom': 'xml.dom.minidom',
  7.     '4DOM': 'xml.dom.DOMImplementation' }
  8. registered = { }
  9.  
  10. def registerDOMImplementation(name, factory):
  11.     registered[name] = factory
  12.  
  13.  
  14. def _good_enough(dom, features):
  15.     for f, v in features:
  16.         if not dom.hasFeature(f, v):
  17.             return 0
  18.             continue
  19.     
  20.     return 1
  21.  
  22.  
  23. def getDOMImplementation(name = None, features = ()):
  24.     import os as os
  25.     creator = None
  26.     mod = well_known_implementations.get(name)
  27.     if mod:
  28.         mod = __import__(mod, { }, { }, [
  29.             'getDOMImplementation'])
  30.         return mod.getDOMImplementation()
  31.     elif name:
  32.         return registered[name]()
  33.     elif os.environ.has_key('PYTHON_DOM'):
  34.         return getDOMImplementation(name = os.environ['PYTHON_DOM'])
  35.     
  36.     if isinstance(features, StringTypes):
  37.         features = _parse_feature_string(features)
  38.     
  39.     for creator in registered.values():
  40.         dom = creator()
  41.         if _good_enough(dom, features):
  42.             return dom
  43.             continue
  44.     
  45.     for creator in well_known_implementations.keys():
  46.         
  47.         try:
  48.             dom = getDOMImplementation(name = creator)
  49.         except StandardError:
  50.             continue
  51.  
  52.         if _good_enough(dom, features):
  53.             return dom
  54.             continue
  55.     
  56.     raise ImportError, 'no suitable DOM implementation found'
  57.  
  58.  
  59. def _parse_feature_string(s):
  60.     features = []
  61.     parts = s.split()
  62.     i = 0
  63.     length = len(parts)
  64.     while i < length:
  65.         feature = parts[i]
  66.         if feature[0] in '0123456789':
  67.             raise ValueError, 'bad feature name: %r' % (feature,)
  68.         
  69.         i = i + 1
  70.         version = None
  71.         if i < length:
  72.             v = parts[i]
  73.             if v[0] in '0123456789':
  74.                 i = i + 1
  75.                 version = v
  76.             
  77.         
  78.         features.append((feature, version))
  79.     return tuple(features)
  80.  
  81.